package com.urfresh.sp.flume.test;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.lang.reflect.Type;

/**
 * Created by urfresh.mark on 2016/9/8.
 */
public class AppDeviceSerializer implements JsonSerializer<AppDevice> {

    public JsonElement serialize(AppDevice appDevice, Type type, JsonSerializationContext context) {
        JsonObject object = new JsonObject();

        //此处按需要实际排序的顺序添加到JsonObject对象中
        object.add("version", context.serialize(appDevice.getVersion()));
        object.add("private_key", context.serialize(appDevice.getPrivateKey()));
        object.add("type", context.serialize(appDevice.getType()));
        object.add("app_id", context.serialize(appDevice.getAppId()));
        object.add("data", context.serialize(appDevice.getData()));
        return object;
    }
}
